import { NodeSize } from '../config'

export default function dbLookup(flow) {
  flow.register('DbLookup', ({ PolygonNode, PolygonNodeModel, h }) => {
    class Node extends PolygonNode {
      getIconShape() {
        return h(
          'svg',
          {
            width: NodeSize,
            height: NodeSize,
            viewBox: '0 0 1024 1024'
          },
          h(
            'path',
            {
              fill: '#3D6480',
              d: 'M949.369905 931.742476l-74.069334-74.069333a117.76 117.76 0 0 0 20.48-66.438095 118.54019 118.54019 0 0 0-118.418285-118.393905c-65.29219 0-118.393905 53.126095-118.393905 118.393905s53.126095 118.393905 118.393905 118.393904a117.76 117.76 0 0 0 64.877714-19.529142l74.386286 74.386285 32.743619-32.743619z m-172.007619-58.660571c-45.129143 0-81.822476-36.717714-81.822476-81.822476s36.717714-81.822476 81.822476-81.822477c45.153524 0 81.846857 36.717714 81.846857 81.822477s-36.717714 81.822476-81.846857 81.822476z'
            }
          ),
          h(
            'path',
            {
              fill: '#FFECCE',
              d: 'M701.44 630.588952c-54.150095 27.184762-164.132571 28.988952-191.829333 28.988953-57.319619 0-111.030857-5.168762-151.235048-14.555429-18.358857-4.266667-33.328762-9.362286-45.031619-15.164952v121.368381c0 14.360381 69.193143 42.276571 196.022857 42.276571h0.024381c30.305524 0 58.977524-1.80419 85.089524-4.973714l106.959238-106.934857v-51.004953z'
            }
          ),
          h(
            'path',
            {
              fill: '#FFECCE',
              d: 'M701.44 481.182476c-54.150095 27.184762-164.132571 28.988952-191.829333 28.988953-57.319619 0-111.030857-5.168762-151.235048-14.555429-18.358857-4.266667-33.328762-9.362286-45.031619-15.164952v127.195428c25.673143 17.383619 95.865905 32.426667 196.266667 32.426667 97.962667 0 166.521905-14.945524 191.829333-32.256v-126.634667z'
            }
          ),
          h(
            'path',
            {
              fill: '#FFECCE',
              d: 'M358.351238 354.523429c-18.334476-4.291048-33.304381-9.362286-45.007238-15.189334v118.905905c25.673143 17.383619 95.865905 32.426667 196.266667 32.426667 97.962667 0 166.521905-14.945524 191.829333-32.256v-118.345143c-54.150095 27.184762-164.132571 29.013333-191.829333 29.013333-57.295238 0-111.006476-5.168762-151.259429-14.555428z'
            }
          ),
          h(
            'path',
            {
              fill: '#FFECCE',
              d: 'M653.628952 335.750095c21.601524-5.12 37.888-11.53219 47.835429-18.358857v-18.529524c-4.681143-12.678095-74.361905-36.059429-196.266667-36.059428-121.002667 0-188.220952 23.186286-191.829333 36.156952v18.188191c25.673143 17.408 95.865905 32.451048 196.266667 32.451047 55.174095-0.024381 106.349714-4.949333 143.993904-13.848381z'
            }
          ),
          h(
            'path',
            {
              fill: '#3D6480',
              d: 'M509.391238 793.502476c-126.829714 0-196.022857-27.940571-196.022857-42.276571v-121.368381c11.678476 5.827048 26.672762 10.898286 45.031619 15.164952 40.20419 9.386667 93.93981 14.555429 151.235048 14.555429 27.696762 0 137.679238-1.80419 191.829333-28.988953v51.004953l41.423238-41.423238v-341.333334c0-71.899429-181.930667-77.507048-237.689905-77.507047-70.119619 0-233.252571 7.558095-233.252571 77.507047v452.388572c0 79.701333 197.802667 83.748571 237.446095 83.748571h0.024381c13.507048 0 26.745905-0.390095 39.692191-0.999619l45.397333-45.421714a715.580952 715.580952 0 0 1-85.113905 4.949333c0.024381 0 0.024381 0 0 0z m192.048762-335.091809c-25.33181 17.310476-93.891048 32.256-191.829333 32.256-100.400762 0-170.593524-15.018667-196.266667-32.426667v-118.905905c11.678476 5.827048 26.648381 10.898286 45.007238 15.189334 40.228571 9.386667 93.96419 14.555429 151.259429 14.555428 27.696762 0 137.679238-1.828571 191.829333-29.013333v118.345143z m-191.829333 181.662476c-100.400762 0-170.593524-15.018667-196.266667-32.426667v-127.195428c11.678476 5.827048 26.672762 10.898286 45.031619 15.164952 40.20419 9.386667 93.93981 14.555429 151.235048 14.555429 27.696762 0 137.679238-1.80419 191.829333-28.988953v126.634667c-25.307429 17.334857-93.866667 32.256-191.829333 32.256z m-196.242286-341.113905c3.608381-12.970667 70.826667-36.156952 191.829333-36.156952 121.904762 0 191.561143 23.381333 196.266667 36.059428v18.529524c-9.947429 6.851048-26.233905 13.238857-47.835429 18.358857-37.64419 8.899048-88.81981 13.824-143.993904 13.824-100.400762 0-170.593524-15.043048-196.266667-32.451047v-18.16381z'
            }
          )
        )
      }

      getLabelShape() {
        return h(
          'text',
          {
            fill: '#000000',
            fontSize: 12,
            x: NodeSize / 2,
            y: NodeSize + 20,
            textAnchor: 'middle',
            dominantBaseline: 'middle'
          },
          '数据库查询'
        )
      }

      getShape() {
        const { x, y, width, height } = this.getAttributes()
        const transform = `matrix(1 0 0 1 ${x - width / 2} ${y - height / 2})`
        return h(
          'g',
          {
            transform
          },
          [
            h(
              'rect',
              {
                rx: 5,
                ry: 5,
                width: NodeSize,
                height: NodeSize,
                fill: '#fff',
                stroke: '#3D6380',
                strokeWidth: 1
              }
            ),
            this.getIconShape(),
            this.getLabelShape()
          ]
        )
      }
    }
    class Model extends PolygonNodeModel {
      constructor(data, graphModel) {
        super(data, graphModel)
        this.points = [
          [NodeSize / 2, 0],
          [NodeSize, NodeSize / 2],
          [NodeSize / 2, NodeSize],
          [0, NodeSize / 2]
        ]
      }
    }

    return {
      view: Node,
      model: Model
    }
  })
}
